//
//  SinaVisitorViewController.swift
//  SinaWeibo
//
//  Created by 王朝阳 on 2016/10/23.
//  Copyright © 2016年 wangzhaoyang. All rights reserved.
//

import UIKit

class SinaVisitorViewController: UIViewController {
    
    //判断用户是否登录的标识
    var isLogin: Bool = SinaUserAccountViewModel.sharedTools.isLogin
    //访客视图
    var visitorView: SinaVisitorView?
    
    
    override func loadView() {
        
        //如果登录
        if isLogin {
            view = tableView
        }else {
            
            setupVisitorView()
        }
    }
    //创建访问者视图
    private func setupVisitorView() {
        
        //        //设置背景颜色
        //        visitorView.backgroundColor = SinaRandomColor()
        //创建视图
        visitorView = SinaVisitorView()
        //实例化闭包
        visitorView?.closure = {[weak self] in
            
            self?.loginClick()
        }
        view = visitorView
        setupNav()
        
    }
    
    //MARK: - 设置导航条
    private func setupNav() {
        navigationItem.leftBarButtonItem = UIBarButtonItem(setHighlightedImgName: nil, title: "注册", target: self, action: #selector(loginClick))
        navigationItem.rightBarButtonItem = UIBarButtonItem(setHighlightedImgName: nil, title: "登录", target: self, action: #selector(loginClick))
    }
    
    //MARK: - 点击事件
    @objc private func loginClick() {
        print("弹出登录界面")
        let OAuthVC = SinaOAuthViewController()
        let OAuthNav = SinaNavigationController(rootViewController: OAuthVC)
        present(OAuthNav, animated: true, completion: nil)
    }
    
    
    override func viewDidLoad() {
        super.viewDidLoad()
    }
    //MARK: - 懒加载控件
    lazy var tableView: UITableView = UITableView()
}
